package cn.neusoft.yuejian307.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cn.neusoft.yuejian307.R;
import cn.neusoft.yuejian307.bean.User;
import cn.neusoft.yuejian307.listener.UserListener;
import cn.neusoft.yuejian307.model.UserModel;

import static cn.neusoft.yuejian307.GloableVirable.USERID;

public class TrainAplly extends AppCompatActivity implements UserListener<User>{
    private MyTitle myTitle;
    private ImageView  pic;
    private TextView activity_name,apply_price,must,apply,sum;
    private EditText user_name,apply_userphone;
    private Intent intent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train_aplly);
        intent = getIntent();
        init();
    }
    private void init(){
        myTitle = (MyTitle)findViewById(R.id.tt);
        myTitle.setTitle("培训报名");
        pic = (ImageView)findViewById(R.id.pic);
        Picasso.with(TrainAplly.this).load(intent.getStringExtra("s2")).into(pic);
        activity_name = (TextView)findViewById(R.id.activity_name);
        activity_name.setText(intent.getStringExtra("s3"));
        apply_price = (TextView)findViewById(R.id.apply_price);
        apply_price.setText(intent.getStringExtra("s4"));
        must = (TextView)findViewById(R.id.must);
        must.setText(intent.getStringExtra("s5"));
        user_name = (EditText)findViewById(R.id.user_name);
        apply_userphone = (EditText)findViewById(R.id.apply_userphone);
        apply = (TextView)findViewById(R.id.apply);
        sum = (TextView)findViewById(R.id.sum);
        sum.setText(intent.getStringExtra("s4"));
        apply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                apply();
            }
        });

    }
    private void apply(){
        String name = user_name.getText().toString();
        String phone = apply_userphone.getText().toString();
        UserModel userModel = new UserModel();
        userModel.trianApplyData(this,Integer.parseInt(intent.getStringExtra("s1")),USERID,name
                ,intent.getStringExtra("s4"),phone);

    }

    @Override
    public void onResponse(User user) {
        if (user.getSuccess() == 1){
            Toast.makeText(TrainAplly.this,"报名成功",Toast.LENGTH_LONG).show();
            finish();
        }else{
            Toast.makeText(TrainAplly.this,"请按规定填写数据",Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(TrainAplly.this,"符文服务器超时",Toast.LENGTH_LONG).show();
    }
}
